package com.zhengtoon.mctoon.conv.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.LinkedHashMap;

public class CertficateUtils {

    private static final Logger log = LoggerFactory.getLogger(CertficateUtils.class);

    private static String certapplyUrl = SysConfig.getPropertyValue("certapply.url");

    private static String certapplyAppToken = SysConfig.getPropertyValue("certapply.appToken");

    private static final String CERTAPPLY_API_OPEN_GETUSERID_URL = "api/queryToonNoByUserId";

    /**
     * 获取userId
     *
     * @param userId userid
     */
    public static boolean getCertApply(String userId) {
        try {
            String queryUserIdUrl = certapplyUrl + CERTAPPLY_API_OPEN_GETUSERID_URL;
            LinkedHashMap<String, String> queryUserIdParam = new LinkedHashMap<>();
            queryUserIdParam.put("appToken", certapplyAppToken);
            queryUserIdParam.put("userId", userId);
            String apptokenJson = HttpXmlClient.httpGet(queryUserIdUrl, queryUserIdParam);
            JSONObject jsonObject = JSON.parseObject(apptokenJson);
            String toonNo = jsonObject.getString("data");
            log.info("实名认证userId查toonNo="+toonNo);
            if (StringUtils.isBlank(toonNo)) {
            	log.info("toonNo为空");
                return false;
            }
        } catch (Exception e) {
            log.error("获取的toonNo发生异常", e);
            return false;
        }
        return true;
    }


}
